package com.etone.android.test.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import android.graphics.Bitmap;
import android.util.Log;
import android.view.View;

/**
 * android桌面工具类
 * 
 * @author LiuWeiJie
 * @date 2012-1-6
 */
public class ViewUtils {

	/**
	 * 屏幕截屏
	 * 
	 * @param view
	 *            屏幕视图
	 * @param name
	 *            保存文件
	 */
	public static void takeScreenShot(final View view, final String name,final String path) {
		view.setDrawingCacheEnabled(true);
		view.buildDrawingCache();
		Bitmap b = view.getDrawingCache();
		FileOutputStream fos = null;
		try {
			File dir = new File(path);
			if (!dir.exists()) {
				dir.mkdirs();
			}
			fos = new FileOutputStream(path + name + ".jpg");
			if (fos != null) {
				b.compress(Bitmap.CompressFormat.JPEG, 90, fos);
				fos.flush();
				fos.close();
			}
		} catch (IOException e) {
			Log.e("etone", e.getMessage());
		}finally{
			if (fos != null){
				try {
					fos.close();
					b=null;
				} catch (IOException e) {
					e.printStackTrace();
					Log.e("etone", e.getMessage());
				}
				
			}
		}
	}
}
